using System;
using System.Collections.Generic;
using System.Text;

using System.Management.Automation;

namespace Microsoft.PowerShell.CmdletManagement
{
    public class PsSpecCmdletUtils
    {
        public struct Constants
        {
            public static string ServiceUri = "http://TODO_WEBSERVICE_HOST/cmdletdesigner/Cmdlet.asmx";
        }

        internal static bool IsValidProjectName(string name)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(name, "^[-a-zA-Z0-9_ ]+$");
        }

        internal static bool IsValidWildcardedProjectName(string name)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(name, "^[-a-zA-Z0-9_ *]+$");
        }

        internal static bool IsValidNounName(string name)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(name, "^[a-zA-Z0-9]+$");
        }

        internal static bool IsValidParameterName(string name)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(name, "^[a-zA-Z0-9]+$");
        }

        internal static bool IsValidWildcardedNounName(string name)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(name, "^[a-zA-Z0-9*]+$");
        }

        internal static string ConvertWildcardToSqlWildcard(string name)
        {
            if (String.IsNullOrEmpty(name))
                return "%";
            else
                return name.Replace("*", "%");
        }

        internal static string ConvertEnumToSqlWildcard(Enum value)
        {
            if(value.ToString() == "Unspecified")
                return "%";
            else
                return value.ToString();
        }

        internal static string GetStringList<T>(T[] items)
        {
            return GetStringList<T>(items, ",");
        }

        internal static string GetStringList<T>(T[] items, string splitter)
        {
            string result = null;

            if (items != null)
            {
                for (int item = 0; item < items.Length; item++)
                {
                    if (item > 0) result += splitter;
                    result += items[item];
                }
            }

            return result;
        }
    }
}
